 define(['template','cookie','url','bootstrap'], (template,cookie) => {
       class Header {
            constructor () {
                this.init().then(()=>{
                  this.cardCount();
                  this.search();
                  this.showName()
                  this. tuichu()
                })
            }
            init(){
              return new Promise(resolve =>{
                 $('header').load('../html/header.html',()=>{
                    resolve();
                 })
              })
           }
            search(){
                $("input").focus(function () {
                  $('.sousuo').show()
                  $(this).on('keyup',() =>{
                    $.get('../libs/class_name.json',resp =>{
                      if(resp.code === 200){
                        let {classli} = resp.body
                        $('.sousuo').html(template('classList',{classli}))
                      }
                    })
                    $('.sousuo').on('mousedown','li',function(){
                       $("input").val($(this).html())
                    })
                })
              })
              $("input").blur(function(){
                $('.sousuo').hide()
              })
           }
            cardCount(){
                let card = localStorage.getItem('card');
                let count = 0
                if(card){
                    card = JSON.parse(card)
                    count = card.reduce((sum,shop) =>{
                          sum += shop.count;
                          return sum
                        },0)
                }
                $('.lis a span,.gocard span').html(count)
            }
            showName(){
                if( $.cookie('phone')){
                  $('.lasttwo').hide()
                  $('.lastlog').show()
                }else{
                  $('.lasttwo').show()
                  $('.lastlog').hide()
                }
           }
           tuichu(){
             let _this = this
             $(".lastlog span").on('click',function(){
              $.cookie('phone','',{expires:-1,path:'/'})
              $.cookie('passone','',{expires:-1,path:'/'})
              _this.showName()
             })
           }
          }
          return new Header()
 })
